<?php

namespace Modules\Api\Http\Controllers;

use Illuminate\Http\Request;
use Modules\Api\Service\StoreCarService;

class StoreCarController extends BaseController
{
    /**
     * 添加商品到购物车
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function add_to_car(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id();

        $res = StoreCarService::add_one((array)$arr_input);

        return response_json($res);
    }

    /**
     * 获取购物车商品列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function get_to_car_list(Request $request)
    {
        $data['type'] = $request->get('type', '');
        $data['user_id'] = api_user_id();//用户id

        $res = StoreCarService::get_list((array)$data);

        return response_json($res);
    }

    /**
     * 加减购物车中商品数量
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function change_num(Request $request)
    {
        $arr_input = $request->all();

        $res = StoreCarService::change_num((array)$arr_input);

        return response_json($res);
    }

    /**
     * 修改购物车中商品规格
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function change_product(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id();

        $res = StoreCarService::change_product((array)$arr_input);

        return response_json($res);
    }

    /**
     * 删除购物车中的商品（批量）
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delete(Request $request)
    {
        $arr_input = $request->all();
        $arr_input['user_id'] = api_user_id();

        $res = StoreCarService::delete((array)$arr_input);

        return response_json($res);
    }
}